package package1;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Calendar;
import javax.swing.Timer;

/**
 * Clase JFrame1
 *
 * @author Luis Angel Arranz Peinado
 */
public class JFrame1 extends javax.swing.JFrame {

    Calendar today;
    int hh, mm, ss;
    
    
    Timer timer = new Timer(1000, new ActionListener() {

    @Override
        public void actionPerformed(ActionEvent e) {
            today = Calendar.getInstance();
            hh = today.get(Calendar.HOUR_OF_DAY);
            mm = today.get(Calendar.MINUTE);
            ss = today.get(Calendar.SECOND);
            jLabelHora.setText(hh+":"+mm+":"+ss);
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    });
    
    /**
     * Creates new form JFrame1
     */
    public JFrame1() {
        initComponents();
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jButtonStart = new javax.swing.JButton();
        jButtonStop = new javax.swing.JButton();
        jButtonActivate = new javax.swing.JButton();
        jButtonDesactivate = new javax.swing.JButton();
        jLabelHora = new javax.swing.JLabel();
        jProgressBarHH = new javax.swing.JProgressBar();
        jProgressBarMM = new javax.swing.JProgressBar();
        jProgressBarSS = new javax.swing.JProgressBar();
        jSpinnerHoras = new javax.swing.JSpinner();
        jSpinnerMinutos = new javax.swing.JSpinner();
        jSpinnerSegundos = new javax.swing.JSpinner();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("AnalogClock");
        setBounds(new java.awt.Rectangle(400, 400, 400, 400));
        setResizable(false);
        getContentPane().setLayout(new java.awt.GridLayout());

        jPanel1.setLayout(null);

        jButtonStart.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jButtonStart.setText("START");
        jButtonStart.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStartActionPerformed(evt);
            }
        });
        jPanel1.add(jButtonStart);
        jButtonStart.setBounds(20, 20, 100, 40);

        jButtonStop.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jButtonStop.setText("STOP");
        jButtonStop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStopActionPerformed(evt);
            }
        });
        jPanel1.add(jButtonStop);
        jButtonStop.setBounds(120, 20, 100, 40);

        jButtonActivate.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jButtonActivate.setText("ACTIVATE");
        jPanel1.add(jButtonActivate);
        jButtonActivate.setBounds(220, 20, 100, 40);

        jButtonDesactivate.setFont(new java.awt.Font("Tahoma", 0, 10)); // NOI18N
        jButtonDesactivate.setText("DESACTIVATE");
        jPanel1.add(jButtonDesactivate);
        jButtonDesactivate.setBounds(320, 20, 100, 40);

        jLabelHora.setFont(new java.awt.Font("Verdana", 1, 36)); // NOI18N
        jLabelHora.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel1.add(jLabelHora);
        jLabelHora.setBounds(20, 270, 400, 90);
        jPanel1.add(jProgressBarHH);
        jProgressBarHH.setBounds(20, 140, 400, 30);
        jPanel1.add(jProgressBarMM);
        jProgressBarMM.setBounds(20, 180, 400, 30);
        jPanel1.add(jProgressBarSS);
        jProgressBarSS.setBounds(20, 220, 400, 30);
        jPanel1.add(jSpinnerHoras);
        jSpinnerHoras.setBounds(130, 80, 50, 30);
        jPanel1.add(jSpinnerMinutos);
        jSpinnerMinutos.setBounds(190, 80, 50, 30);
        jPanel1.add(jSpinnerSegundos);
        jSpinnerSegundos.setBounds(250, 80, 50, 30);

        getContentPane().add(jPanel1);

        setSize(new java.awt.Dimension(462, 415));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStartActionPerformed
        timer.start();
    }//GEN-LAST:event_jButtonStartActionPerformed

    private void jButtonStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStopActionPerformed
        timer.stop();
    }//GEN-LAST:event_jButtonStopActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JFrame1().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonActivate;
    private javax.swing.JButton jButtonDesactivate;
    private javax.swing.JButton jButtonStart;
    private javax.swing.JButton jButtonStop;
    private javax.swing.JLabel jLabelHora;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JProgressBar jProgressBarHH;
    private javax.swing.JProgressBar jProgressBarMM;
    private javax.swing.JProgressBar jProgressBarSS;
    private javax.swing.JSpinner jSpinnerHoras;
    private javax.swing.JSpinner jSpinnerMinutos;
    private javax.swing.JSpinner jSpinnerSegundos;
    // End of variables declaration//GEN-END:variables
}
